<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>地图展示</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
        .info {
            z-index: 999;
            width: auto;
            min-width: 22rem;
            padding: .75rem 1.25rem;
            margin-left: 1.25rem;
            position: fixed;
            top: 1rem;
            background-color: #fff;
            border-radius: .25rem;
            font-size: 14px;
            color: #666;
            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
        }
    </style>
    <script src="js/axios-0.18.0.js"></script>
    <script src="js/vuejs-2.5.16.js"></script>
    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=0F4xPcPCyD0Hx7ZoaGVAtqGqG6kVhOz2"></script>
</head>
<body>
<div class = "info">最新版GL地图命名空间为BMapGL, 可按住鼠标右键控制地图旋转、修改倾斜角度。</div>
<div id="container"></div>
</body>
</html>
<script>
    var latitudeMap;//90+
    var longitudeMap;//90-
    var nickNameMap;
    var avatarMap;
    var addressMap;
    window.onload =  function (){
        //获取上一个页面传过来的ID
        var id = location.search.split("=")[1];
        console.log(id);
        axios.get("/management/findAllUserOnMap?id="+id).then(resp=>{
            latitudeMap=resp.data.Longitude;
            longitudeMap=resp.data.Latitude;
            nickNameMap = resp.data.nickName;
            avatarMap = resp.data.avatar;
            addressMap = resp.data.address;
            console.log(resp.data);
            console.log(latitudeMap);
            console.log(longitudeMap);
            alert(resp.data)
            f();
        });//
    }

    /* axios.get("/management/findAllUserOnMap").then(resp=>{
         loca = resp.data;
         console.log(loca)
         alert("成功连接")
     });*/
    // 创建点标记
    function f() {
        var map = new BMapGL.Map('container'); // 创建Map实例

        map.centerAndZoom(new BMapGL.Point(latitudeMap,longitudeMap), 12); // 初始化地图,设置中心点坐标和地图级别
        map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
        console.log(latitudeMap);
        console.log(longitudeMap);


        // 在地图上添加点标记
        var point = new BMapGL.Point(this.latitudeMap,this.longitudeMap)
        var marker = new BMapGL.Marker(point);
        map.addOverlay(marker);
        // 创建图文信息窗口
        var sContent = `<h4 style='margin:0 0 5px 0;'>`+nickNameMap+`</h4>
    <img style='float:right;margin:0 4px 22px' id='imgDemo' src='`+avatarMap+`' width='139' height='104'/>
    <p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>
   `+addressMap+`
    </p></div>`;
        var infoWindow = new BMapGL.InfoWindow(sContent);
// marker添加点击事件
        marker.addEventListener('click', function () {
            this.openInfoWindow(infoWindow);
            // 图片加载完毕重绘infoWindow
            document.getElementById('imgDemo').onload = function () {
                infoWindow.redraw(); // 防止在网速较慢时生成的信息框高度比图片总高度小，导致图片部分被隐藏
            };
        });

    /*    var opts = {
            width : 200,     // 信息窗口宽度
            height: 100,     // 信息窗口高度
            title : nickNameMap , // 信息窗口标题
            message:"这里是故宫"
        }
        var infoWindow = new BMapGL.InfoWindow(addressMap, opts);  // 创建信息窗口对象
        marker.addEventListener("click", function(){
            map.openInfoWindow(infoWindow, point); //开启信息窗口
        });*/

    }


</script>